import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    # 定义下面的函数

    def set_default_header(self):
        # 后面的*可以换成ip地址，意为允许访问的地址
        self.set_header('Access-Control-Allow-Origin', '*')
        self.set_header('Access-Control-Allow-Headers', 'x-requested-with')
        self.set_header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE')
    def get(self):
        self.write("Hello World")
    def post(self, *args, **kwargs):
        self.set_header('Access-Control-Allow-Origin', '*')
        self.write("mark")

def make_app():
    return tornado.web.Application([
(r"/api/session",MainHandler),
])

def main():
    app = make_app()
    app.listen(8080)
    tornado.ioloop.IOLoop.current().start()

if __name__=="__main__":
    main()